<?php
// 配置文件
require_once 'config.php';
?>
<!DOCTYPE html>
<html>
<head>
    <style>
        .timer-btn {
            padding: 12px 24px;
            font-size: 1em;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            display: block;
            margin-bottom: 25px;
        }
        .timer-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0,0,0,0.15);
        }
        .timer-btn:active {
            transform: translateY(0);
        }
        .button-container {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-bottom: 25px;
        }
    </style>
    <title>学习计时器</title>
    <style>
        body { 
            font-family: sans-serif; 
            padding: 20px;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        h1 { 
            font-size: 2em; 
            margin-bottom: 20px;
            text-align: center;
            color: #2c3e50;
        }
        .timer-display { 
            font-size: 3em;
            text-align: center;
            margin: 20px 0;
            font-family: 'Courier New', monospace;
            color: #2c3e50;
            text-shadow: 0 0 10px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }
        .timer-controls { 
            display: flex; 
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
        }
        button { 
            padding: 12px 24px; 
            font-size: 1em;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0,0,0,0.15);
        }
        button:active {
            transform: translateY(0);
        }
        button:disabled {
            background: #cccccc;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        .preset-buttons {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
        }
        a { 
            display: inline-block;
            margin-top: 20px;
            color: #333;
            text-decoration: none;
            font-size: 1.2em;
        }
    </style>
</head>
<body>
    <div class="button-container">
        <a href="index.php" class="timer-btn">返回首页</a>
    </div>
    <h1>学习计时器</h1>
    
    <div class="timer-display" id="time">00:00:00</div>
    
    <div class="timer-controls">
        <button class="timer-btn" id="startBtn">开始</button>
        <button class="timer-btn" id="pauseBtn" disabled>暂停</button>
        <button class="timer-btn" id="resetBtn">重置</button>
    </div>
    <script>
        let timer;
        
        let hours = 0;
        let minutes = 0;
        let seconds = 0;
        let isRunning = false;
        
        
        function updateDisplay() {
            
            const h = hours;
            const m = minutes;
            const s = seconds;
            
            const timeElement = document.getElementById('time');
            timeElement.style.transform = 'scale(1.1)';
            timeElement.style.color = '#e74c3c';
            
            setTimeout(() => {
                timeElement.style.transform = 'scale(1)';
                timeElement.style.color = '#2c3e50';
            }, 300);
            
            timeElement.textContent = 
                `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
        }
        
        document.getElementById('startBtn').addEventListener('click', function() {
            if (!isRunning) {
                isRunning = true;
                this.disabled = true;
                document.getElementById('pauseBtn').disabled = false;
                
                timer = setInterval(function() {
                    seconds++;
                    if (seconds >= 60) {
                        seconds = 0;
                        minutes++;
                        if (minutes >= 60) {
                            minutes = 0;
                            hours++;
                            if (hours >= 24) {
                                hours = 0;
                            }
                        }
                    }
                    updateDisplay();
                }, 1000);
            }
        });
        
        document.getElementById('pauseBtn').addEventListener('click', function() {
            if (isRunning) {
                isRunning = false;
                clearInterval(timer);
                document.getElementById('startBtn').disabled = false;
                this.disabled = true;
            }
        });
        
        document.getElementById('resetBtn').addEventListener('click', function() {
            isRunning = false;
            clearInterval(timer);
            seconds = 0;
            updateDisplay();
            document.getElementById('startBtn').disabled = false;
            document.getElementById('pauseBtn').disabled = true;
        });
        
        
    </script>
</body>
</html>